#include "caidan1groupbutton.h"
#include "ui_caidan1groupbutton.h"
#include "framecore.h"

Caidan1GroupButton::Caidan1GroupButton ( QWidget* parent ) :
    HuanButton ( parent ),
    bBigShow ( false ),
    ui ( new Ui::Caidan1GroupButton )
{
    ui->setupUi ( this );
}

Caidan1GroupButton::~Caidan1GroupButton()
{
    delete ui;
}

Caidan1GroupButton::Caidan1GroupButton ( const Caidan1GroupButton& other )
{
    Caidan1GroupButton& ref = *this;
    ref = other;
}

Caidan1GroupButton& Caidan1GroupButton::operator = ( const Caidan1GroupButton& other )
{
    Caidan1GroupButton& ref = *this;
    ref.setAllCaidanButton ( other.allCaidanButton() );
    return ref;
}

bool Caidan1GroupButton::operator == ( const Caidan1GroupButton& other )
{
    Caidan1GroupButton& ref = *this;
    const QList<Caidan1Button*>& otherBtnList = other.allCaidanButton();

    if ( btnList == otherBtnList )
        return true;

    return false;
}

QList<Caidan1Button*>& Caidan1GroupButton::allCaidanButton()
{
    return btnList;
}

const QList<Caidan1Button*>& Caidan1GroupButton::allCaidanButton() const { return btnList; }

void Caidan1GroupButton::setAllCaidanButton ( const QList<Caidan1Button*>& btnList )
{
    this->btnList = btnList;
}

void Caidan1GroupButton::insertCaidanButton ( int index, Caidan1Button* btn )
{
    if ( index < 0 || index > btnList.size() )
        return;

    btnList.insert ( index, btn );
    return;
}

void Caidan1GroupButton::AddCaidanButton ( Caidan1Button* btn )
{
    //这里是无法解解释的，按说应该直接赋值，可是在macOS llvm下，这里竟然用了外边的引用，而没有新生成。
    btnList.push_back ( btn );
}

void Caidan1GroupButton::removeCaidanButton ( Caidan1Button* rming )
{
    QMutableListIterator<Caidan1Button*> itor ( btnList );

    while ( itor.hasNext() )
    {
        Caidan1Button* btn = itor.next();

        if ( btn == rming )
        {
            btnList.removeOne ( btn );
            break;
        }
    }
}

void Caidan1GroupButton::updateCaidanButton()
{

    int size = btnList.size();

    if ( size <= 0 )
        return;

    for ( int i = 0; i < size; i++ )
    {

        Caidan1Button* btn = btnList[i];

        QRect rrr0 = calculatePosition ( this->widget(), i,
                                         50,//big
                                         15, //little
                                         2,//num
                                         90 );
        pline() << rrr0;
        QFont font = qApp->font();
        font.setPixelSize ( 6 );
        btn->setTextFont ( font );
        btn->setIconSize ( QSize ( 30, 30 ) );
        btn->setGeometry ( rrr0 );
    }

}

void Caidan1GroupButton::setBigGroup ( bool bigOne ) { bBigShow = bigOne; }
